package xlj.lib.android.base.push;

import android.content.Context;
import android.content.SharedPreferences;

import com.igexin.sdk.PushManager;

public class PushSettings {

    private static PushSettings pushSettings;

    private Context context;

    private String userId = "undefined";

    private int pushIcon;

    public static PushSettings pushSettings() {
        if (pushSettings == null) {
            pushSettings = new PushSettings();
        }
        return pushSettings;
    }

    public int getPushIcon() {
        return pushIcon;
    }

    public void setNotifyId(int notifyId) {
        NotificationPoster.setNotifyId(notifyId);
    }

    public void init(Context context, int pushIcon) {
        this.context = context;
        this.pushIcon = pushIcon;
    }

    public void setUserId(String userId) {
        this.userId = userId;
        if (isPushOff()) {
            PushManager.getInstance().turnOffPush(context);
        } else {
            PushManager.getInstance().turnOnPush(context);
        }
    }

    public void pushOff(boolean isOff) {
        SharedPreferences sp = context.getSharedPreferences("user_" + userId,Context.MODE_PRIVATE );
        sp.edit().putBoolean("push_off",isOff).apply();
        if (isOff) {
            PushManager.getInstance().turnOffPush(context);
        } else {
            PushManager.getInstance().turnOnPush(context);
        }
    }

    public boolean isPushOff() {
        if(context != null) {
            SharedPreferences sp = context.getSharedPreferences("user_" + userId, Context.MODE_PRIVATE);
            return sp.getBoolean("push_off", false);
        }
        return false;
    }
    public void showNotificationDetai(boolean isShow) {
        SharedPreferences sp = context.getSharedPreferences("user_" + userId,Context.MODE_PRIVATE );
        sp.edit().putBoolean("show_notification_detail",isShow).apply();
    }

    public boolean isShowNotificationDetail() {
        SharedPreferences sp = context.getSharedPreferences("user_" + userId,Context.MODE_PRIVATE );
        return sp.getBoolean("show_notification_detail",false);
    }

    public void voiceOff(boolean isOff) {
        SharedPreferences sp = context.getSharedPreferences("user_" + userId,Context.MODE_PRIVATE );
        sp.edit().putBoolean("voice_off",isOff).apply();
    }

    public boolean isVoiceOff() {
        SharedPreferences sp = context.getSharedPreferences("user_" + userId,Context.MODE_PRIVATE );
        return sp.getBoolean("voice_off",false);
    }

    public void vibrateOff(boolean isOff) {
        SharedPreferences sp = context.getSharedPreferences("user_" + userId,Context.MODE_PRIVATE );
        sp.edit().putBoolean("vibrare_off",isOff).apply();
    }

    public boolean isVibrateOff() {
        SharedPreferences sp = context.getSharedPreferences("user_" + userId,Context.MODE_PRIVATE );
        return sp.getBoolean("vibrare_off",false);
    }
}
